/**
\file Win32.h
*/
#pragma once
#include <lostlbase.h>
#include <fstream>
#include <System.h>

namespace Microsoft { namespace Win32 {

	union RegistryHive
	{
	public:
		RegistryHive(int value) : m_value(value) {}
		enum :unsigned { ClassesRoot = 0x80000000, CurrentUser = 0x80000001, LocalMachine = 0x80000002, Users = 0x80000003, PerformanceData = 0x80000004, CurrentConfig=0x80000005, DynData=0x80000006 };
		operator unsigned() { return m_value; };
	private:
		unsigned	m_value;
	};

	union RegistryView
	{
	public:
		RegistryView(int value) : m_value(value) {}
		enum :unsigned { Default = 0, Registry64 = 0x0100, Registry32 = 0x0200 };
		operator unsigned() { return m_value; };
	private:
		unsigned	m_value;
	};

	/** Safely handles a registry key */
	class SafeRegistryHandle
	{
		friend class RegistryKey;
	public:
		/** Safely copies a key. */
		SafeRegistryHandle(const SafeRegistryHandle &source);
		~SafeRegistryHandle();
	private:
		HKEY		m_hKey;
		REGSAM		m_regSam;
	};

	class RegistryKey
	{
		friend class Registry;
	public:
		/** Closes the key and flushes it to disk if its contents have been modified. */
		void	Close();
		/** Gets a SafeRegistryHandle object that represents the registry key that the current RegistryKey object encapsulates. */
		SafeRegistryHandle	get_Handle()	{ return m_hKey; }
		/** Retrieves the name of the key. */
		string	get_Name();
		/** Retrieves the count of sub-keys of the current key. */
		int		get_SubKeyCount();
		/** Retrieves the count of values in the key. */
		int		get_ValueCount();
		/** Gets the view that was used to create the registry key.*/
		RegistryView	get_View();
		static	RegistryKey OpenBaseKey( RegistryHive hkey, RegistryView view = RegistryView::Default );
	private:
		SafeRegistryHandle	m_hKey;
		RegistryKey( RegistryHive hkey );
	};

	class Registry
	{
	public:
		/** Defines the types (or classes) of documents and the properties associated with those types. This field reads the Windows registry base key HKEY_CLASSES_ROOT. */
		static RegistryKey get_ClassesRoot();
		/** Contains configuration information pertaining to the hardware that is not specific to the user. This field reads the Windows registry base key HKEY_CURRENT_CONFIG. */
		static RegistryKey get_CurrentConfig();
		/** Contains information about the current user preferences. This field reads the Windows registry base key HKEY_CURRENT_USER */
		static RegistryKey get_CurrentUser();
		/** Obsolete. Contains dynamic registry data. This field reads the Windows registry base key HKEY_DYN_DATA. */
		static RegistryKey get_DynData();
		/**	Contains the configuration data for the local machine. This field reads the Windows registry base key HKEY_LOCAL_MACHINE. */
		static RegistryKey get_LocalMachine();
		/**	Contains performance information for software components. This field reads the Windows registry base key HKEY_PERFORMANCE_DATA. */
		static RegistryKey get_PerformanceData();
		/**	Contains information about the default user configuration. This field reads the Windows registry base key HKEY_USERS. */
		static RegistryKey get_Users();
	private:
	};

} }
